package com.jjyd.crlp.services.impl;

import com.jjyd.crlp.domain.entity.UserAuth;
import com.jjyd.crlp.domain.entity.Users;
import com.jjyd.crlp.domain.entity.type.LoginType;
import com.jjyd.crlp.domain.repository.UserAuthRepo;
import com.jjyd.crlp.domain.repository.UsersRepo;
import com.jjyd.crlp.model.dto.login.LoginDto;
import com.jjyd.crlp.services.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {

    @Autowired
    private UserAuthRepo userAuthRepo;
    @Autowired
    private UsersRepo usersRepo;


    /**
     * 登陆接口
     *
     * @param loginDto
     * @return
     */
    @Override
    public UserAuth login(LoginDto loginDto) {
        LoginType loginType = loginDto.getLoginType();
        String password = loginDto.getPassword();
        String username = loginDto.getUsername();
        UserAuth userAuth = userAuthRepo.getByRemoveFalseAndLoginTypeAndCredentialAndIdentifier(loginType, password, username);
        return userAuth;
    }

    /**
     * 获得用户信息
     *
     * @param id
     * @return
     */
    @Override
    public Users getUserInfo(Integer id) {
        Users users = usersRepo.getByRemoveFalseAndId(id);
        return users;
    }
}
